<!--
 功能描述：论坛增加
 开发人：wanghw
 开发日期：2019/11/12
 -->
<template lang="pug">
  kalix-dialog.user-add(bizKey="Message" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:submitBefore="submitBefore" )
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item(label="帖子主题" prop="theme" v-bind:label-width="labelWidth" v-bind:rules="rules.theme")
        el-input(v-model="formModel.theme" style="width:80%")
      el-form-item.short(label="发帖人" prop="userName" v-bind:label-width="labelWidth" v-bind:rules="rules.userName")
        el-input(v-model="formModel.userName" style="width:80%")
      el-form-item(label="评论时间" prop="messageDateTime" v-bind:label-width="labelWidth" v-bind:rules="rules.messageDateTime")
        kalix-datetime-picker(v-model="formModel.messageDateTime" style="width:80%" type="date")
      el-form-item(label="帖子标题" prop="messageTitle" v-bind:label-width="labelWidth" v-bind:rules="rules.messageTitle")
        el-input(v-model="formModel.messageTitle" style="width:80%")
      el-form-item(label="帖子内容" prop="messageContent" v-bind:label-width="labelWidth" v-bind:rules="rules.messageContent")
        el-input(v-model="formModel.messageContent" style="width:80%")
      el-form-item(label="图片" prop="photo" v-bind:label-width="labelWidth")
        kalix-clansman-upload(:action="action" v-on:filePath="getFilePath" fileType="img" tipText="只能上传jpg/png文件" )
      el-form-item(label="文档" prop="file" v-bind:label-width="labelWidth")
        kalix-clansman-upload(:action="action" v-on:filePath="getFilePath" fileType="Upfile" tipText="上传文件格式包含pdf、doc、docx、txt、xls、xlsx、ppt" )
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {MessageURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  export default {
    name: 'messageAdd',
    components: {KalixClansmanUpload},
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        rules: {
          messageContent: [{required: true, message: '请输入帖子内容', trigger: 'blur'}],
          userName: [{required: true, message: '请输入发帖人', trigger: 'blur'}]
        },
        targetURL: MessageURL,
        labelWidth: '110px',
        action: baseURL + '/camel/rest/upload',
        filePathArr: [],
        fileNameArr: [],
        items: [],
        options: []
      }
    },
    mounted() {
      this.getUname()
    },
    methods: {
      init(dialogOption) {
        console.log('---------this.formModel.uid------------', this.formModel.uid)
      },
      getUname() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users'
        }).then(res => {
          this.options = res.data.data
        })
      },
      getUid(val) {
        let obj = {}
        obj = this.options.find((item) => {
          return item.id === val
        })
        this.formModel.userName = obj.name
      },
      getFilePath(filePath, fileName) {
        console.log('--getFilePath---', filePath)
        console.log('--fileName---', fileName)
        this.filePathArr.push(filePath)
        this.fileNameArr.push(fileName)
      },
      submitBefore(baseDialog, callBack) {
        console.log('===FilePath=================', this.filePathArr)
        let filePath = ''
        if (this.filePathArr.length) {
          this.filePathArr.forEach(e => {
            filePath += e + ','
          })
          filePath = filePath.substr(0, filePath.length - 1)
        }
        let fileName = ''
        if (this.fileNameArr.length) {
          this.fileNameArr.forEach(e => {
            fileName += e + ','
          })
          fileName = fileName.substr(0, fileName.length - 1)
        }
        baseDialog.formModel.photo = filePath
        baseDialog.formModel.imgName = fileName
        callBack()
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
</style>
